package com.jade.linkong.controller;

import com.jade.common.annotation.Log;
import com.jade.common.core.controller.BaseController;
import com.jade.common.core.domain.AjaxResult;
import com.jade.common.core.page.TableDataInfo;
import com.jade.common.enums.BusinessType;
import com.jade.common.utils.poi.ExcelUtil;
import com.jade.linkong.domain.LkProject;
import com.jade.linkong.domain.LkProjectProcess;
import com.jade.linkong.service.ILkProjectProcessService;
import com.jade.linkong.service.ILkProjectService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 项目进度调度任务Controller
 * 
 * @author jade
 * @date 2020-08-06
 */
@Controller
@RequestMapping("/linkong/process")
public class LkProjectProcessController extends BaseController
{
    private String prefix = "linkong/process";

    @Autowired
    private ILkProjectProcessService lkProjectProcessService;
    @Autowired
    private ILkProjectService projectService;

    @RequiresPermissions("linkong:process:view")
    @GetMapping()
    public String process()
    {
        return prefix + "/process";
    }

    /**
     * 查询项目进度调度任务列表
     */
    @RequiresPermissions("linkong:process:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LkProjectProcess lkProjectProcess)
    {
        startPage();
        List<LkProjectProcess> list = lkProjectProcessService.selectLkProjectProcessList(lkProjectProcess);
        return getDataTable(list);
    }

    /**
     * 导出项目进度调度任务列表
     */
    @RequiresPermissions("linkong:process:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LkProjectProcess lkProjectProcess)
    {
        List<LkProjectProcess> list = lkProjectProcessService.selectLkProjectProcessList(lkProjectProcess);
        ExcelUtil<LkProjectProcess> util = new ExcelUtil<LkProjectProcess>(LkProjectProcess.class);
        return util.exportExcel(list, "process");
    }

    /**
     * 新增项目进度调度任务
     */
    @GetMapping("/add")
    public String add(ModelMap map)
    {
        List<LkProject> lkProjects = projectService.selectLkProjectList(new LkProject());
        map.put("projects", lkProjects);
        return prefix + "/add";
    }

    /**
     * 新增保存项目进度调度任务
     */
    @RequiresPermissions("linkong:process:add")
    @Log(title = "项目进度调度任务", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LkProjectProcess lkProjectProcess)
    {
        return toAjax(lkProjectProcessService.insertLkProjectProcess(lkProjectProcess));
    }

    /**
     * 修改项目进度调度任务
     */
    @GetMapping("/edit/{processId}")
    public String edit(@PathVariable("processId") Long processId, ModelMap mmap)
    {
        LkProjectProcess lkProjectProcess = lkProjectProcessService.selectLkProjectProcessById(processId);
        mmap.put("lkProjectProcess", lkProjectProcess);
        return prefix + "/edit";
    }

    /**
     * 修改保存项目进度调度任务
     */
    @RequiresPermissions("linkong:process:edit")
    @Log(title = "项目进度调度任务", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LkProjectProcess lkProjectProcess)
    {
        return toAjax(lkProjectProcessService.updateLkProjectProcess(lkProjectProcess));
    }

    /**
     * 删除项目进度调度任务
     */
    @RequiresPermissions("linkong:process:remove")
    @Log(title = "项目进度调度任务", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lkProjectProcessService.deleteLkProjectProcessByIds(ids));
    }

    /***
     *  进度任务启用/禁用
     * @Author wupujian
     * @Description
     * @Date  2020/8/7
     * @Param [lkProjectProcess]
     * @return com.jade.common.core.domain.AjaxResult
     **/
    @PostMapping( "/enableOrNotProcess")
    @ResponseBody
    public AjaxResult enableOrNotProcess(LkProjectProcess lkProjectProcess){
        return toAjax(lkProjectProcessService.enableOrNotProcess(lkProjectProcess));
    }

}
